const utils = require('j7/utils');

class BaseWrap {

  #writeLock = false;

  constructor(json, metaClass) {
    this._json = json;
    //this._metaClass = metaClass;
    this._metaName = metaClass['wrapClassName'];
  }

  lock() {
    //this.#writeLock = true;
  }

  _getHandler() {
    return {
      get: (obj, prop) => {
        if (prop in obj._json) {
          let val = obj._json[prop];
          if (utils.isArray(val)) {
            return new Proxy(val, {
              set: () => {
                console.log(33333);
              }
            });
          } else if (utils.isObject(val)) {
            return new Proxy(val, {
              set: () => {
                console.log(33333);
              }
            });
          } else {
            return val;
          }
        }
        return prop in obj ? obj[prop] : null;
      },
      set: (obj, prop, val) => {
        if (this.#writeLock) {
          console.log(111111);
        } else {
          Reflect.set(obj, prop, val);
        }
        return true;
      }
    };
  }

  getMetaName() {
    return this._metaName;
  }

}

exports.BaseWrap = BaseWrap;
